package zcw.com.lib_leet_code;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by 朱城委 on 2021/9/9.<br><br>
 *
 * 中等：组合
 */
public class Topic77 {

    public static void main(String[] args) {
        Topic77 instance = new Topic77();

        System.out.println(instance.combine(4, 2));
        System.out.println(instance.combine(1, 1));
    }

    public List<List<Integer>> combine(int n, int k) {
        List<List<Integer>> result = new ArrayList<>();

        helper(result, new ArrayList<>(), 1, n, k);
        return result;
    }

    private void helper(List<List<Integer>> result, List<Integer> list, int start, int n, int k) {
        if(list.size() == k) {
            result.add(new ArrayList<>(list));
            return ;
        }

        for(int i = start; i <= n; i++) {
            list.add(i);
            helper(result, list, i + 1, n, k);
            list.remove(list.size() - 1);
        }
    }
}
